﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using RealState.BLL;
using log4net;
using RealState.BusinessObjects;
using RealState.Utils;

namespace RealState.W.AdminControl
{
    public partial class SupportEdit : System.Web.UI.UserControl
    {
        protected ILog log = LogManager.GetLogger(typeof(SupportEdit));
        private SupportsBLL m_SupportsBLL;
        private Supports m_SupportsDO;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    m_SupportsBLL = new SupportsBLL();
                    m_SupportsDO = new Supports();
                    try
                    {
                        m_SupportsDO = m_SupportsBLL.GetSupports(Int32.Parse(Request.QueryString["ID"]));
                        txtFullName.Text = m_SupportsDO.Fullname;
                        txtYahoo.Text = m_SupportsDO.Yahoo;
                    }
                    catch (Exception ex)
                    {
                        log.Equals(ex.Message);
                    }
                    finally
                    {
                        m_SupportsDO = null;
                        m_SupportsBLL = null;
                    }
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            m_SupportsBLL = new SupportsBLL();
            m_SupportsDO = new Supports();
            try
            {
                m_SupportsDO.ID = Int32.Parse(Request.QueryString["ID"]);
                m_SupportsDO.Fullname = txtFullName.Text;
                m_SupportsDO.Yahoo = txtYahoo.Text;
                int result = m_SupportsBLL.UpdateSupports(m_SupportsDO);
                if (result > 0)
                {
                    JavaScript.Success("Sửa đổi thành công", Page, Request.Url.ToString());
                }
                else
                    JavaScript.Error("Có lỗi xảy ra ", Page);
            }
            catch (Exception ex)
            {
                log.Equals(ex.Message);
            }
            finally
            {
                m_SupportsDO = null;
                m_SupportsBLL = null;
            }
        }
    }
}